//
//  YLMenberPrivilegeViewController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/12.
//  Copyright © 2017年 she1323. All rights reserved.
//   会员特权

#import "YLMemberPrivilegeViewController.h"
#import <Masonry.h>
#import "YLMemberPrivilegeHeaderView.h"
#import "YLGlobeHeader.h"
#import "YLMemberPrivilegeViewModel.h"
#import "YLMemberPrivilegeTableViewCell.h"
@interface YLMemberPrivilegeViewController ()

@property (nonatomic, strong) YLMemberPrivilegeViewModel *viewModel;

@end

@implementation YLMemberPrivilegeViewController

- (YLMemberPrivilegeViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[YLMemberPrivilegeViewModel alloc] initWithPrivilegeId:self.privilegeId];
    }
    return _viewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"会员特权";
    __weak typeof(self) weakSelf = self;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(weakSelf.view);
    }];
    
    YLMemberPrivilegeHeaderView *header = [[YLMemberPrivilegeHeaderView alloc] init];
    header.frame = CGRectMake(0, 0, YLScreenW, YLScreenW * 492 / 1082.0);
    self.tableView.tableHeaderView = header;
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([YLMemberPrivilegeTableViewCell class]) bundle:nil] forCellReuseIdentifier:[YLMemberPrivilegeTableViewCell cellID]];
    
    [[self.viewModel.privilegeDetailCommand execute:nil] subscribeNext:^(id  _Nullable x) {
        header.imageName = weakSelf.viewModel.privilegeImg;
        [weakSelf.tableView reloadData];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - tableView 代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.viewModel.models.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YLMemberPrivilegeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[YLMemberPrivilegeTableViewCell cellID]];
    cell.model = self.viewModel.models[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}


@end
